package com.group.orderproject.Controller;

import com.group.orderproject.Service.DishService;
import com.group.orderproject.pojo.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    DishService dishService;
    @RequestMapping("/findAll")
    public List<Dish> findAll(){
        return dishService.findAll();
    }
    @PostMapping("/sava")
    public Integer add(@RequestBody Dish dish){
        return dishService.save(dish);
    }
    @RequestMapping("/select+{DishName}")
    public List<Dish> selectByName(@PathVariable String DishName){
        return dishService.selectBy(DishName);
    }
    @GetMapping("/page")
    public Map<String,Object> selectPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@RequestParam String DishName){
        Map<String,Object> res=new HashMap<>();
        DishName="%"+DishName+"%";
        List<Dish> list=dishService.selectPage(pageNum,pageSize,DishName);
        Integer num=dishService.selectAll(DishName);
        int statue;
        if(list!=null){
            statue=200;
        }else{
            statue=0;
        }
        res.put("data",list);
        res.put("total",num);
        res.put("pageNum",pageNum);
        res.put("pageSize",pageSize);
        res.put("statue",statue);
        return res;
    }
    @PostMapping("/deleteOne") //删除
    public Integer delete(@RequestBody Integer id){
        return dishService.deleteById(id);
    }

    @PostMapping("/del/batch")
    public Integer deleteByIds(@RequestBody List<Integer> ids){
        return dishService.deleteByIds(ids);
    }


}
